﻿namespace MDXStudio
{
    using MDXParser;
    using Microsoft.NetMap.Visualization;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using WeifenLuo.WinFormsUI.Docking;

    public class DependenciesWindow : DockContent
    {
        private IContainer components;
        private System.Windows.Forms.DataGridView dataGridViewDependencies;
        private DataGridViewTextBoxColumn dgvDependenciedColIn;
        private DataGridViewTextBoxColumn dgvDependenciedColName;
        private DataGridViewTextBoxColumn dgvDependenciedColOut;
        private Microsoft.NetMap.Visualization.NetMapControl netMapControl;
        private SplitContainer splitContainer5;

        public DependenciesWindow()
        {
            this.InitializeComponent();
        }

        private void dataGridViewDependencies_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.RowIndex >= 0) && (e.ColumnIndex >= 0))
            {
                System.Windows.Forms.DataGridView view = sender as System.Windows.Forms.DataGridView;
                Dictionary<string, Vertex> dictionary = new Dictionary<string, Vertex>();
                foreach (DataGridViewCell cell in view.SelectedCells)
                {
                    if (cell.Tag != null)
                    {
                        foreach (Vertex vertex in cell.Tag as ICollection<Vertex>)
                        {
                            if (!dictionary.ContainsKey(vertex.Name))
                            {
                                dictionary.Add(vertex.Name, vertex);
                            }
                        }
                    }
                }
                if (dictionary.Count != 0)
                {
                    (view.Tag as DependencyGraph).Visualize(this.netMapControl, dictionary.Values, null);
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(DependenciesWindow));
            this.splitContainer5 = new SplitContainer();
            this.dataGridViewDependencies = new System.Windows.Forms.DataGridView();
            this.dgvDependenciedColName = new DataGridViewTextBoxColumn();
            this.dgvDependenciedColOut = new DataGridViewTextBoxColumn();
            this.dgvDependenciedColIn = new DataGridViewTextBoxColumn();
            this.netMapControl = new Microsoft.NetMap.Visualization.NetMapControl();
            this.splitContainer5.Panel1.SuspendLayout();
            this.splitContainer5.Panel2.SuspendLayout();
            this.splitContainer5.SuspendLayout();
            ((ISupportInitialize) this.dataGridViewDependencies).BeginInit();
            base.SuspendLayout();
            this.splitContainer5.BorderStyle = BorderStyle.Fixed3D;
            this.splitContainer5.Dock = DockStyle.Fill;
            this.splitContainer5.Location = new Point(0, 0);
            this.splitContainer5.Name = "splitContainer5";
            this.splitContainer5.Panel1.Controls.Add(this.dataGridViewDependencies);
            this.splitContainer5.Panel2.Controls.Add(this.netMapControl);
            this.splitContainer5.Size = new Size(0x124, 0x111);
            this.splitContainer5.SplitterDistance = 0x5d;
            this.splitContainer5.TabIndex = 2;
            this.dataGridViewDependencies.AllowUserToAddRows = false;
            this.dataGridViewDependencies.AllowUserToDeleteRows = false;
            this.dataGridViewDependencies.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridViewDependencies.Columns.AddRange(new DataGridViewColumn[] { this.dgvDependenciedColName, this.dgvDependenciedColOut, this.dgvDependenciedColIn });
            this.dataGridViewDependencies.Dock = DockStyle.Fill;
            this.dataGridViewDependencies.Location = new Point(0, 0);
            this.dataGridViewDependencies.Name = "dataGridViewDependencies";
            this.dataGridViewDependencies.RowHeadersVisible = false;
            this.dataGridViewDependencies.Size = new Size(0x59, 0x10d);
            this.dataGridViewDependencies.TabIndex = 0;
            this.dataGridViewDependencies.CellClick += new DataGridViewCellEventHandler(this.dataGridViewDependencies_CellClick);
            this.dgvDependenciedColName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            this.dgvDependenciedColName.HeaderText = "Name";
            this.dgvDependenciedColName.Name = "dgvDependenciedColName";
            this.dgvDependenciedColOut.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            this.dgvDependenciedColOut.HeaderText = "Out";
            this.dgvDependenciedColOut.Name = "dgvDependenciedColOut";
            this.dgvDependenciedColOut.Width = 0x31;
            this.dgvDependenciedColIn.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            this.dgvDependenciedColIn.HeaderText = "In";
            this.dgvDependenciedColIn.Name = "dgvDependenciedColIn";
            this.dgvDependenciedColIn.Width = 0x29;
            this.netMapControl.AllowVertexDrag = true;
            this.netMapControl.BackColor = SystemColors.Window;
            this.netMapControl.Dock = DockStyle.Fill;
            this.netMapControl.Location = new Point(0, 0);
            this.netMapControl.MouseSelectionMode = MouseSelectionMode.SelectVertexOnly;
            this.netMapControl.Name = "netMapControl";
            this.netMapControl.ShowToolTips = false;
            this.netMapControl.Size = new Size(0xbf, 0x10d);
            this.netMapControl.TabIndex = 0;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x124, 0x111);
            base.Controls.Add(this.splitContainer5);
            base.HideOnClose = true;
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.Name = "DependenciesWindow";
            base.TabText = "Dependencies";
            this.Text = "Dependencies";
            this.splitContainer5.Panel1.ResumeLayout(false);
            this.splitContainer5.Panel2.ResumeLayout(false);
            this.splitContainer5.ResumeLayout(false);
            ((ISupportInitialize) this.dataGridViewDependencies).EndInit();
            base.ResumeLayout(false);
        }

        internal System.Windows.Forms.DataGridView DataGridView
        {
            get
            {
                return this.dataGridViewDependencies;
            }
        }

        internal Microsoft.NetMap.Visualization.NetMapControl NetMapControl
        {
            get
            {
                return this.netMapControl;
            }
        }
    }
}

